<{Tinclude "commom/admin_header"}>
 <section id="container" >
      
      <!--顶部-->
      <{Tinclude"commom/admin_inner_header"}>
      <!--顶部-->
      
       <{Tinclude"commom/admin_left_menu"}>
       
       <section id="main-content">
          <section class="wrapper">
          	<h3><i class="<{if $___menuinfo["iconclass"]}><{$___menuinfo["iconclass"]}><{else}>fa fa-list-ul<{/if}>"></i><{$___menuinfo["base_name"]}></h3>
                <div class="row mt">
                    <div class="col-md-12">
                       <div class="form-panel">  
                           
                           
                           
                           <div class="btn-group col-md-6">
     <button type="button" class="btn btn-primary" id="addgoods">添加新商品</button>
  <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
    批量操作 <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu">
    <li><a href="javascript:void(0);" onclick="bitch_down();">批量下架</a></li>
      <li class="divider"></li>
    <li><a href="javascript:void(0);" onclick="bitch_up();">批量上架</a></li>
     <li class="divider"></li>
        <li><a href="javascript:void(0);" onclick="bitch_del();">批量删除</a></li>
    
  </ul>
</div>
                           
                           
                           <div class="col-md-6 text-right">               
             <form class="form-inline" role="form" action="<{echo Common::RewriteUrl($jp_arg["c"],$jp_arg["a"]);}>"  method="post">
    <input type="hidden" name="<{echo Common::RewriteUrl($jp_arg['c'],$jp_arg['a']);}>"/>
  <div class="form-group">
    <label for="base_name" class="sr-only">商品名称</label>
    <input type="text" class="form-control" value="<?php if(isset($jp_arg['base_name']))echo $jp_arg['base_name'];?>" name="base_name" id="base_name" placeholder="商品名称">
  </div>
    <div class="form-group">
             <?php if(isset($pinfo)){?>
 <?php foreach($pinfo as $k=>$val){?>
     <?php if($k==0){?>
     <select class="form-control parent_id" name="parent_id[]">
      <option value="0">顶级分类</option>
 
          <?php foreach($val["data"] as $value){?>
         
          <option value="<?php echo $value['id'];?>" <?php if($value["id"]==$val["selected"]) echo "selected";?> ><?php echo $value['base_name'];?></option>
        
  
         <?php }?>
  </select>
     <?php }else{?>
     <span class="menuchildrenall">  
         <select class="form-control col-md-1 col-xs-4 menuchildren"  onchange="menuselectchange(this)" name="parent_id[]">
          <option value="-1">请选择分类</option>
    
          <?php foreach($val["data"] as $value){?>
           <option value="<?php echo $value['id'];?>" <?php if($value["id"]==$val["selected"]) echo "selected";?> ><?php echo $value['base_name'];?></option>
          <?php }?>
       
         
  </select>

</span>
     <?php }?>
     <?php }?>
<?php }?>
    </div>
    <button type="submit" name="search" class="btn btn-default">搜索</button>
  <script>
      function menuselectchange(obj){
             var cid=$(obj).val();

             
         
             var thisobj=$(obj).parent();
                if(cid>0){
                 
               
              
                  $.post("<{echo Common::RewriteUrl("goodcate","public_get_children");}>",{"parent_id":cid},function(data){
                  $(".menuchildrenall").each(function(){
                      if($(this).index()>thisobj.index()){
                          $(this).remove();
                      }
                  });
                  text=data.replace(/(^\s*)|(\s*$)/g,'');
                  if(text.length>0){
                  $(".menuparent").append(data);
                  }
                 
      });
             }

        }
    $('.parent_id').bind('change', function () {
      var cid=$(this).val();
      var parent=$(this).parent();
    
      if(cid!=0){
      
      $.post("<{echo Common::RewriteUrl("goodcate","public_get_children");}>",{"parent_id":cid},function(data){
          $(".menuchildrenall").remove();
          parent.append(data);
         
      });
    }else{
      
        $(".menuchildrenall").remove();
    }
    });
    
  </script>
</form>        
                           </div>                  
                           
                           
                           
                           
                           
                           <section id="no-more-tables">                   
  <table class="table table-striped table-condensed table-hover cf">
      <thead class="cf">
        <tr>
          <th> 
              <input type="checkbox" id="checkall">全选
          </th>
          <th>缩略图</th>
          <th>商品名称</th>
          <th>所属类别</th>
          <th>销售价格</th>
          <th>状态</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
          <?php if(isset($list)){?>
          <?php foreach($list as $val){?>
        <tr>
            <td class="hidden-phone"> <input type="checkbox" class="checkbox" value="<?php echo $val["id"];?>" /></td>
            <td data-title="缩略图"  class="jphidden-phone"><a href="<{echo Common::RewriteUrl("goods","edit","&id=".$val["id"]);}>" ><img src="<?php echo $val["thumb"];?>" class="img-responsive img-thumbnail" /></a></td>
          <td data-title="商品名称"><?php echo $val["base_name"];?></td>
          <td data-title="所属类别"><?php echo $val["cate_name"];?></td>
          <td data-title="销售价格"><?php echo $val["sale_price"];?>(元/斤)</td>
           <td data-title="状态"><?php if($val["status"])echo"上架";else echo "下架";?></td>
          <td  data-title="操作">
              <div class="btn-group">  
              <a class="btn btn-primary btn-xs" href="<{echo Common::RewriteUrl("goods","edit","&id=".$val["id"]);}>" ><span class="glyphicon glyphicon-edit"></span></a><a class="btn btn-danger btn-xs" href="<{echo Common::RewriteUrl("goods","delete","&id=".$val["id"]);}>"><span class="glyphicon glyphicon-trash"></span></a>
              </div>
          </td>
        </tr>
        <?php }?>
        <?php }?>
      </tbody>
    </table>
         </section>                
                           
                           
                           
                           
                           <div class="col-md-12 text-center">
                           <?php Temp::Tinclude("commom/pager");?>
                           </div>
                           <div class="clearfix"></div>
                           
                       </div>
                    </div>
                </div>
          </section>
       </section>
 </section>
<script>
    $("#checkall").click(function(){
        if(true ==$(this).get(0).checked){
            $("input[type='checkbox']").each(function(){
                $(this).get(0).checked=true;
            });
        }else{
          $("input[type='checkbox']").each(function(){
                $(this).get(0).checked=false;
            });
        }
    });
    function bitch_down(){
         var ids=new Array();
        $(".checkbox").each(function(){
            if($(this).get(0).checked){
                ids.push($(this).val());
            }
        });
        if(ids.length>0){
            $.post("<{echo Common::RewriteUrl("goods","public_ajax_down");}>",{"ids":ids},function(data){
                if(data.status==1){
                    alert("批量下架成功!");
                    window.location.reload();
                }else{
                     alert("批量下架失败!");
                }
            },"json");
        }
    }
    function bitch_up(){
         var ids=new Array();
        $(".checkbox").each(function(){
            if($(this).get(0).checked){
                ids.push($(this).val());
            }
        });
        if(ids.length>0){
            $.post("<{echo Common::RewriteUrl("goods","public_ajax_up");}>",{"ids":ids},function(data){
                if(data.status==1){
                    alert("批量上架成功!");
                    window.location.reload();
                }else{
                     alert("批量上架失败!");
                }
            },"json");
        }
    }
    function bitch_del(){
        var ids=new Array();
        $(".checkbox").each(function(){
            if($(this).get(0).checked){
                ids.push($(this).val());
            }
        });
        if(ids.length>0){
            $.post("<{echo Common::RewriteUrl("goods","public_ajax_delete");}>",{"ids":ids},function(data){
                if(data.status==1){
                    alert("删除成功!");
                    window.location.reload();
                }else{
                     alert("删除失败!");
                }
            },"json");
        }
    }
    $("#addgoods").click(function(){
        window.location.href="<{echo Common::RewriteUrl("goods","index");}>";
    });
</script>
<{Tinclude"commom/admin_footer"}>